//
//  TopicListViewController.swift
//  ModernFoodWebsite
//
//  Created by apple on 16/5/31.
//  Copyright © 2016年 Lonnie. All rights reserved.
//

import UIKit

class TopicListViewController: BaseTableViewController {
    
    let composeButton = UIButton()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.rowHeight = UITableViewAutomaticDimension
        self.tableView.estimatedRowHeight = 100
        title = "" 
    }
 
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        navigationController!.view.addSubview(composeButton)
        composeButton.setImage(UIImage(named: "icon_write_topic"), forState: .Normal)
        composeButton.addTarget(self, action: #selector(TopicListViewController.publish), forControlEvents: .TouchUpInside)
        composeButton.snp_makeConstraints { (make) in
            make.trailing.equalTo(composeButton.superview!).offset(-20)
            make.bottom.equalTo(self.navigationController!.view).offset(-70)
        }
    }
    
    func publish() {
        self.performSegueWithIdentifier("publish", sender: nil)
    }
    
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
        composeButton.removeFromSuperview()
        
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return 10
    }

   
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("item", forIndexPath: indexPath)

        // Configure the cell...

        return cell
    }
 
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        performSegueWithIdentifier("detail", sender: nil)
    }

 }
